<template src="./index.html"></template>

<script>
import MedicalRecordChildbearingHistoryService from "../../../../../../_services/medicalRecordChildbearingHistory.service";
export default {
  name: "TianDingPatientMeBirthHistoryModifyComponent",
  data() {
    return {
      params: {
        ChildbearID: 0,
        UserID: 0,
        PregnancyTime: "",
        PregnancyWay: "0",
        IsChildbed: "0",
        EmbryoStatus: "",
        ChildbearingWay: "0",
        EmbryoDetail: "0",
        StopDevelopment_Week: "6",
        PROM_Week: "20",
        FGR_Week: "12",
        Preeclampsia_Week: "20",
        DeadFetus_Week: "20",
        OAF_Week: "20",
        EmbryoDye: "0",
        Exception: "无",
        KeepPregnantMedicine: "无",
        OtherMedicine: "无",
        Hematoncus: "无",
        Pathology: "无",
        EmbryoEnding: "0",
        Hospital: "无",
        PregnancyWeek: "39"
      },
      EmbryoStatusList: [
        {
          key: 0,
          value: "停止发育",
          isRadio: true,
          check: false,
          show: true
        },
        {
          key: 1,
          value: "未着床",
          isRadio: true,
          check: false,
          show: true
        },
        {
          key: 2,
          value: "生化",
          isRadio: true,
          check: false,
          show: true
        },
        {
          key: 3,
          value: "宫外孕",
          isRadio: true,
          check: false,
          show: true
        },
        {
          key: 4,
          value: "葡萄胎",
          isRadio: true,
          check: false,
          show: true
        },
        {
          key: 5,
          value: "胎膜早破",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 6,
          value: "胎儿生长受限",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 7,
          value: "子痫前期",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 8,
          value: "死胎",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 9,
          value: "畸形儿",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 10,
          value: "主动放弃",
          isRadio: true,
          check: false,
          show: true
        }
      ], //胚胎
      EmbryoDetailList: [
        {
          value: "0",
          label: "无卵黄囊+无胎芽+无胎心"
        },
        {
          value: "1",
          label: "有卵黄囊+无胎芽+无胎心"
        },
        {
          value: "2",
          label: "有卵黄囊+有胎芽+无胎心"
        },
        {
          value: "3",
          label: "有卵黄囊+有胎芽+有胎心"
        }
      ], //胚胎情况
      EmbryoEndingList: [
        {
          value: "0",
          label: "主动人流"
        },
        {
          value: "1",
          label: "未着床"
        },
        {
          value: "2",
          label: "生化妊娠"
        },
        {
          value: "3",
          label: "完全流产"
        },
        {
          value: "4",
          label: "药物流产"
        },
        {
          value: "5",
          label: "清宫"
        },
        {
          value: "6",
          label: "宫外孕"
        },
        {
          value: "7",
          label: "葡萄胎"
        },
        {
          value: "8",
          label: "引产"
        },
        {
          value: "9",
          label: "刨宫产"
        }
      ], //结局
      KeepPregnantMedicineList: [
        {
          key: 0,
          value: "无",
          isRadio: true,
          check: false,
          show: true
        },
        {
          key: 1,
          value: "阿司匹林",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 2,
          value: "低分子肝素",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 3,
          value: "强的松/美卓乐",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 4,
          value: "地塞米松",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 5,
          value: "孕酮",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 6,
          value: "雌激素",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 7,
          value: "免疫球蛋白",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 8,
          value: "TNF抑制剂(益赛普/强克) ",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 9,
          value: "粒细胞刺激因子(瑞白/赛能)",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 10,
          value: "HCG针",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 11,
          value: "二甲双胍",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 12,
          value: "羟氯喹(纷乐/赛能)",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 13,
          value: "溴隐亭",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 14,
          value: "优甲乐",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 15,
          value: "钙片",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 16,
          value: "叶酸",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 17,
          value: "维生素E",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 18,
          value: "维生素C",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 19,
          value: "维生素D",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 20,
          value: "维生素B6",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 21,
          value: "维生素B12",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 22,
          value: "坤灵丸",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 23,
          value: "爱乐维",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 24,
          value: "环胞素",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 25,
          value: "主动免疫",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 26,
          value: "中药",
          isRadio: false,
          check: false,
          show: true
        }
      ], //保胎药
      showPregnancyTime: false, //受孕/移植年月
      PregnancyTime: "", //受孕/移植年月
      showPregnancyWeek: false, //孕周
      showEmbryoDetail: false, //胚胎情况
      showEmbryoEnding: false, //结局
      showEmbryoStatus: false, //胚胎
      showKeepPregnantMedicine: false, //保胎药
      showItem: false,
      PregnancyWeekList: [], //孕周
      showStopDevelopment_Week: false, //停止发育孕周
      StopDevelopment_WeekList: [], //停止发育孕周
      showPROM_Week: false, ////胎膜早破孕周
      PROM_WeekList: [], //胎膜早破孕周
      showFGR_Week: false, //生长受限孕周
      FGR_WeekList: [], //生长受限孕周
      showPreeclampsia_Week: false, //子痫前期孕周
      Preeclampsia_WeekList: [], //子痫前期孕周
      showDeadFetus_Week: false, //死胎孕周
      DeadFetus_WeekList: [], //死胎孕周
      showOAF_Week: false, //畸形儿孕周
      OAF_WeekList: [], //畸形儿孕周
      isHematoncus: "0", //血肿
      isPathology: "0", //病理
      load: false
    };
  },
  mounted() {
    let birthHostory = JSON.parse(this.local$.getItem("tdBirthHistory"));
    if (birthHostory !== null) {
      this.params = birthHostory;
      this.dataFormat(this.params);
      if (!this.params.PregnancyWay) {
        this.params.PregnancyWay = "0";
      }
      if (!this.params.IsChildbed) {
        this.params.IsChildbed = "0";
      }
      if (!this.params.ChildbearingWay) {
        this.params.ChildbearingWay = "0";
      }
      if (!this.params.EmbryoDetail) {
        this.params.EmbryoDetail = "0";
      }
      if (!this.params.StopDevelopment_Week) {
        this.params.StopDevelopment_Week = "6";
      }
      if (!this.params.PROM_Week) {
        this.params.PROM_Week = "20";
      }
      if (!this.params.FGR_Week) {
        this.params.FGR_Week = "12";
      }
      if (!this.params.Preeclampsia_Week) {
        this.params.Preeclampsia_Week = "20";
      }
      if (!this.params.DeadFetus_Week) {
        this.params.DeadFetus_Week = "20";
      }
      if (!this.params.OAF_Week) {
        this.params.OAF_Week = "20";
      }
      if (!this.params.EmbryoDye) {
        this.params.EmbryoDye = "0";
      }
      if (!this.params.EmbryoEnding) {
        this.params.EmbryoEnding = "0";
      }
      if (!this.params.PregnancyWeek) {
        this.params.PregnancyWeek = "39";
      }

      this.EmbryoStatusList.filter((v, i, a) => {
        let include = this.params.EmbryoStatus.split(",").includes(v.value);
        v.check = include;
        return a;
      });
      this.KeepPregnantMedicineList.filter((v, i, a) => {
        let include = this.params.KeepPregnantMedicine.split(",").includes(
          v.value
        );
        v.check = include;
        return a;
      });
    }
    this.utils$.getNumberLabel(this.PregnancyWeekList, 38, 42, "周");
    this.utils$.getNumberLabel(this.StopDevelopment_WeekList, 6, 28, "周");
    this.utils$.getNumberLabel(this.PROM_WeekList, 20, 36, "周");
    this.utils$.getNumberLabel(this.FGR_WeekList, 12, 36, "周");
    this.utils$.getNumberLabel(this.Preeclampsia_WeekList, 20, 36, "周");
    this.utils$.getNumberLabel(this.DeadFetus_WeekList, 20, 36, "周");
    this.utils$.getNumberLabel(this.OAF_WeekList, 20, 36, "周");

    this.getPregnancyWay(this.params.PregnancyWay);
    this.load = true;
  },
  methods: {
    getPregnancyTime(event) {
      this.params.PregnancyTime = event;
    },
    getPregnancyWay(event) {
      console.log(event);
      this.EmbryoStatusList.filter((v, i, a) => {
        if (event === "0") {
          if (v.key === 1) {
            v.show = false;
            this.params.EmbryoStatus = "";
          } else {
            v.show = true;
          }
        } else {
          v.show = true;
        }
        return a;
      });
    },
    getPregnancyWeek(event) {
      this.showPregnancyWeek = false;
    },
    getEmbryoDetail(event) {
      this.showEmbryoDetail = false;
    },
    getEmbryoEnding(event) {
      this.showEmbryoEnding = false;
    },
    getStopDevelopment_WeekList(event) {
      this.showStopDevelopment_Week = false;
    },
    getPROM_Week(event) {
      this.showPROM_Week = false;
    },
    getFGR_Week(event) {
      this.showFGR_Week = false;
    },
    getPreeclampsia_Week(event) {
      this.showPreeclampsia_Week = false;
    },
    getDeadFetus_Week(event) {
      this.showDeadFetus_Week = false;
    },
    getOAF_Week(event) {
      this.showOAF_Week = false;
    },
    changeEmbryoStatus() {
      if (this.showEmbryoStatus) {
        this.showEmbryoStatus = false;
      } else if (!this.showEmbryoStatus) {
        this.showEmbryoStatus = true;
      }
    },
    getEmbryoStatus(event) {
      console.log(event);
      let temp = [];
      event.forEach(value => {
        switch (value) {
          case 1:
          case 2:
            this.params.EmbryoEnding = value.toString();
            this.showItem = true;
            break;
          case 3:
            this.params.EmbryoEnding = "6";
            this.showItem = true;
            break;
          case 4:
            this.params.EmbryoEnding = "7";
            this.showItem = true;
            break;
          case 10:
            this.params.EmbryoEnding = "0";
            this.showItem = true;
            break;
          default:
            this.showItem = false;
            break;
        }
      });

      if (
        event[0] === 0 ||
        event[0] === 1 ||
        event[0] === 2 ||
        event[0] === 3 ||
        event[0] === 4 ||
        event[0] === 10
      ) {
        this.showEmbryoStatus = !this.showEmbryoStatus;
        let item = this.EmbryoStatusList.find(i => i.key === event[0]);
        temp.push(item.value);
      } else {
        event.forEach(value => {
          let item = this.EmbryoStatusList.find(i => i.key === value);
          temp.push(item.value);
        });
      }
      this.params.EmbryoStatus = temp.toString();
    },
    getKeepPregnantMedicine(event) {
      let temp = [];
      if (event[0] === 0) {
        this.showKeepPregnantMedicine = false;
        let item = this.KeepPregnantMedicineList.find(i => i.key === event[0]);
        temp.push(item.value);
      } else {
        event.forEach(value => {
          let item = this.KeepPregnantMedicineList.find(i => i.key === value);
          temp.push(item.value);
        });
      }
      this.params.KeepPregnantMedicine = temp.toString();
    },
    embryoStatusFlag(EmbryoStatusItem) {
      if (this.params.EmbryoStatus) {
        return this.params.EmbryoStatus.split(",").includes(EmbryoStatusItem);
      } else {
        return false;
      }
    },
    dataFormat(data) {
      Object.keys(data).forEach(key => {
        if (data[key] === null) {
          data[key] = "";
        } else if (typeof data[key] === "number") {
          data[key] = data[key].toString();
        }
      });
      return data;
    },
    btnSubmit() {
      if (this.params.IsChildbed === "2") {
        if (!this.params.EmbryoStatus) {
          this.toast$("请选择胚胎");
          return;
        }
        if (this.params.EmbryoDye === "2" || this.showItem) {
          if (!this.params.Exception) {
            this.toast$("请填写异常情况");
            return;
          }
        }
        if (this.isHematoncus === "1" || this.showItem) {
          if (!this.params.Hematoncus) {
            this.toast$("请填写血肿情况");
            return;
          }
        }
        if (this.isPathology === "1" || this.showItem) {
          if (!this.params.Pathology) {
            this.toast$("请填写医院");
            return;
          }
        }
        if (!this.params.Hospital) {
          this.toast$("请填写医院");
          return;
        }
      }
      let user = JSON.parse(this.local$.getItem("tdUser"));
      let params = {
        ChildbearID: parseInt(this.params.ChildbearID),
        UserID: user.UserID,
        PregnancyTime: this.params.PregnancyTime,
        PregnancyWay: this.params.PregnancyWay
          ? parseInt(this.params.PregnancyWay)
          : 0,
        IsChildbed: this.params.IsChildbed
          ? parseInt(this.params.IsChildbed)
          : 0,
        EmbryoStatus: this.params.EmbryoStatus,
        ChildbearingWay: this.params.ChildbearingWay
          ? parseInt(this.params.ChildbearingWay)
          : 0,
        EmbryoDetail: this.params.EmbryoDetail
          ? parseInt(this.params.EmbryoDetail)
          : 0,
        StopDevelopment_Week: this.params.StopDevelopment_Week
          ? parseInt(this.params.StopDevelopment_Week)
          : 0,
        PROM_Week: this.params.PROM_Week ? parseInt(this.params.PROM_Week) : 0,
        FGR_Week: this.params.FGR_Week ? parseInt(this.params.FGR_Week) : 0,
        Preeclampsia_Week: this.params.Preeclampsia_Week
          ? parseInt(this.params.Preeclampsia_Week)
          : 0,
        DeadFetus_Week: this.params.DeadFetus_Week
          ? parseInt(this.params.DeadFetus_Week)
          : 0,
        OAF_Week: this.params.OAF_Week ? parseInt(this.params.OAF_Week) : 0,
        EmbryoDye: this.params.EmbryoDye ? parseInt(this.params.EmbryoDye) : 0,
        Exception: this.params.Exception ? this.params.Exception : "无",
        KeepPregnantMedicine: this.params.KeepPregnantMedicine
          ? this.params.KeepPregnantMedicine
          : 0,
        OtherMedicine: this.params.OtherMedicine,
        Hematoncus: this.params.Hematoncus,
        Pathology: this.params.Pathology,
        EmbryoEnding: this.params.EmbryoEnding
          ? parseInt(this.params.EmbryoEnding)
          : 0,
        Hospital: this.params.Hospital,
        PregnancyWeek: this.params.PregnancyWeek
          ? parseInt(this.params.PregnancyWeek)
          : 0
      };
      console.log(params);
      if (params.ChildbearID > 0) {
        MedicalRecordChildbearingHistoryService.updateChildbearingHistory(
          params
        ).then(response => {
          if (response && response.Data) {
            this.toast$("保存成功");
          } else {
            this.toast$("保存失败");
          }
          this.$router.push({ name: "tdPatientMeMedicalBirthHistory" });
        });
      } else {
        MedicalRecordChildbearingHistoryService.addChildbearingHistory(
          params
        ).then(response => {
          if (response && response.Data) {
            this.toast$("保存成功");
          } else {
            this.toast$("保存失败");
          }
          this.$router.push({ name: "tdPatientMeMedicalBirthHistory" });
        });
      }
    }
  },
  watch: {
    showPregnancyTime(val) {
      if (val) {
        this.utils$.closeTouch();
      } else {
        this.utils$.openTouch();
      }
    }
  }
};
</script>

